TAR = client server node
FUSELIB = `pkg-config fuse --libs`
FUSE_CFLAGS = `pkg-config fuse --cflags`
CFLAGS = -Wall
all:$(TAR)

# Comment/uncomment the following line to disable/enable debugging
DEBUG = y

# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DDNFS_DEBUG # "-O" is needed to expand inlines
else
  DEBFLAGS = -O2
endif

CFLAGS += $(DEBFLAGS)

client:client.o client_func.o dnfs_clnt.o dnfs_xdr.o 	
	cc -o $@ $^ $(FUSELIB) -lm

client.o:client.c 	
	cc -c $< -o $@ $(CFLAGS) $(FUSE_CFLAGS)

client_func.o:client_func.c
	cc -c $< -o $@ $(CFLAGS) $(FUSE_CFLAGS)

dnfs_clnt.o:dnfs_clnt.c 
	cc -c $< -o $@ $(CFLAGS)

dnfs_xdr.o:dnfs_xdr.c 
	cc -c $< -o $@ $(CFLAGS)

dnfs_xdr.c:dnfs.x
	rpcgen -C -M dnfs.x

dnfs_clnt.c:dnfs.x
	rpcgen -C -M dnfs.x

#make server
server:server.o server_svc.o dnfs_xdr.o server_func.o dnfs_clnt.o
	cc -o $@ $^ -lm -lssl

server.o:server.c
	cc -c $< -o $@ $(CFLAGS)

server_func.o:server_func.c
	cc -c $< -o $@ $(CFLAGS)

server_svc.o:server_svc.c
	cc -c $< -o $@ $(CFLAGS)

#dnfs_svc.c:dnfs.x
#	rpcgen -C -M dnfs.x

#make node
node:node.o node_func.o node_svc.o dnfs_xdr.o dnfs_clnt.o
	cc -o $@ $^ -lpthread

node.o:node.c
	cc -c $< -o $@ $(CFLAGS)

node_func.o:node_func.c
	cc -c $< -o $@ $(CFLAGS)

cs_svc.o:cs_svc.c
	cc -c $< -o $@ $(CFLAGS)

so_svc.o:so_svc.c
	cc -c $< -o $@ $(CFLAGS)

co_svc.o:co_svc.c
	cc -c $< -o $@ $(CFLAGS)

clean:
	rm *.o
	rm $(TAR)
